package com.handinfo.android.core.input;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.TextUtils.TruncateAt;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.widget.EditText;

public class DWInputView extends EditText
{
	protected Context m_context;
	private MyTextWatcher m_textWatcher;
	public DWInputView(Context context)
	{
		super(context);
		m_context = context;
		this.setFocusable(true);
		this.setFocusableInTouchMode(true);
		this.setWidth(0);
		this.setHeight(0);
		setDrawingCacheEnabled(false);
		setWillNotDraw(false);
		setWillNotCacheDrawing(false);
		this.setSingleLine(true);
		this.setEllipsize(TruncateAt.END);
		m_textWatcher = new MyTextWatcher(this);
		this.addTextChangedListener(m_textWatcher);
	}

	public InputConnection onCreateInputConnection(EditorInfo outAttrs)
	{
//		return super.onCreateInputConnection(outAttrs);
		InputConnection ic = super.onCreateInputConnection(outAttrs);
		return new DWInputConnectionWrapper(ic, false);
	}
	
	private class MyTextWatcher implements TextWatcher
	{
		private int index = 0;
		private int length = 0;
		private EditText editText;
		
		public MyTextWatcher(EditText editText)
		{
			super();
			this.editText = editText;
		}

		public void onTextChanged(CharSequence s, int start, int before, int count)
		{
		}
		
		public void beforeTextChanged(CharSequence s, int start, int count, int after)
		{
			index = start;
			length = s.length();
		}
		
		public void afterTextChanged(Editable s)
		{
//			if (s.length() > length) {
//				if (s.charAt(index) == '<' || s.charAt(index) == '>') {
//					s.delete(index, index + 1);
//				}
//			}
		}
	}
}
